<!DOCTYPE html>
<html>

<head>
    <title>{$node.node_title}</title>
    {include file="common/header"/}
    <el-card class="box-card" shadow="never">
        <div slot="header" class="clearfix">
            <span>修改基础配置</span>
        </div>
        <div class="text item">
            <el-form ref="form" label-width="80px">
                <el-form-item :label="item.conf_desc?item.conf_desc:item.conf_key" v-for="(item, index) in form"
                    :key="index">
                    <el-input v-model="item.conf_value"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">保存配置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </el-card>
    {include file="common/footer"/}
    <script>
        new Vue({
            el: '#app',
            data() {
                this.getData();
                return {
                    form: []
                }
            },
            methods: {
                getData() {
                    var that = this;
                    axios.post('/api/conf/getBaseConfig', Object.assign({}, PostBase))
                        .then(function (response) {
                            if (response.data.code == CODE_SUCCESS) {
                                that.form = response.data.data;
                            } else {
                                that.$message.error(response.data.msg);
                            }
                        })
                        .catch(function (error) {
                            that.$message.error('服务器内部错误');
                            console.log(error);
                        });
                },
                onSubmit() {
                    var that = this;
                    var postData = {};
                    for (var i = 0; i < that.form.length; i++) {
                        postData[that.form[i].conf_key] = that.form[i].conf_value;
                    }
                    axios.post('/api/conf/updateBaseConfig', Object.assign({}, PostBase, postData))
                        .then(function (response) {
                            if (response.data.code == CODE_SUCCESS) {
                                that.$message({
                                    message: response.data.msg,
                                    type: 'success'
                                });
                            } else {
                                that.$message.error(response.data.msg);
                            }
                        })
                        .catch(function (error) {
                            that.$message.error('服务器内部错误');
                            console.log(error);
                        });
                },
            }
        })
    </script>


</html>